package com.azkj.album.presenter;

import com.azkj.album.dto.LoginBean;
import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.net.exception.ApiException;
import com.azkj.album.view.iview.IRegisterView;
import com.azkj.album.view.widgets.dialog.DialogHelper;

import java.util.Map;

public class RegisterPresenter extends SendSmsPresenter {

    private final IRegisterView iView;

    public RegisterPresenter(IRegisterView iRegisterView) {
        super(iRegisterView);
        this.iView = iRegisterView;

    }


    public void register(Map<String, Object> body) {

        NetworkMaster.getInstance().getCommonService().register(body, new ServiceCallback<BaseResp<LoginBean>>() {
            @Override
            public void onSuccess(BaseResp<LoginBean> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iView.registerSuccess(jsonObj.getData());
                } else {
                    iView.registerFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iView.registerFail(apiException.errorInfo.error);
            }

        });

    }

    public void changePhone(Map<String, Object> body) {
        NetworkMaster.getInstance().getCommonService().changePhone(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                if (jsonObj.getCode() == 1) {
                    iView.changeSuccess(jsonObj.getMsg());
                } else {
                    iView.changeFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iView.changeFail(apiException.errorInfo.error);
            }

        });

    }

    public void changePsd(Map<String, Object> body) {

        NetworkMaster.getInstance().getCommonService().changePsd(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iView.changeSuccess(jsonObj.getMsg());
                } else {
                    iView.changeFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iView.changeFail(apiException.errorInfo.error);
            }

        });


    }


}
